///////////////////////////////////page_parkOrderDetails////////////////////
$(document).on("pageInit", "#page_parkOrderDetails", function(e, pageId, $page) {
	console.log('1')
    my.givetitle('泊车订单详细');
	                $.showPreloader()
      			    var key=my.get_key(my.getCookie('token'))
      			    var store_id=''
      			    var start_time=''
      			    var end_time=''
      			    var is_rent=''
      	    	     //订单详情开始
                    var info={parking_id:sessionStorage.parking_id_parkOrderDetails}
                        info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				$.ajax({
      					url:api.parkingorderinfo,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.toast("订单详情获取失败");
      						},
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{

      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    is_rent=data.info.is_rent
      								    store_id=data.info.store_id
      								    start_time=data.info.parking_starttime
      								    end_time=data.info.parking_endtime
      								    $('.clxhh').text(data.info.brand_chinese_name+''+data.info.cars_name)
      								    $('.usercar_nickname').text(data.info.car_carid)
      								    $('.stores_name').text(data.info.stores_name)
      								    $('.order_startime').text(data.info.parking_starttime)
      								    $('.order_endtime').text(data.info.parking_endtime)
      								    $('.parking_price').text(data.info.parking_price)
      								    if(data.info.zhifu_count!=0){
      								    	for(var i=0;i<data.zhifu_button.length;i++){
      								    		if(data.zhifu_button[i].waitfp_status==0){
      								    			var list='<div class="zfxm-zf bottn btn-zf" style="margin-top: 1rem;" id="'+data.zhifu_button[i].waitfp_id+'" title="'+data.zhifu_button[i].waitfp_cost+'">待支付  '+config.danwei+data.zhifu_button[i].waitfp_cost+'</div>'
      								    			$('.zf-btn-list').empty().append(list)
      								    		}else if(data.zhifu_button[i].waitfp_status==1)
      								    		{
      								    			var list='<div class="zfxm-xq bottn" style="margin-top: 1rem;" id="'+data.zhifu_button[i].waitfp_id+'">已支付  '+config.danwei+data.zhifu_button[i].waitfp_cost+'</div>'
      								    			$('.zf-btn-list').empty().append(list)
      								    		}
      								    	}
      								    	$('.zfxm-zf').click(function(){
      								    		sessionStorage.park_waitfp_id=$(this).attr('id')
      								    		sessionStorage.park_parking_id=sessionStorage.parking_id_parkOrderDetails
                    	                        //$.router.loadPage("zhifu_Park.html");
                                                $.router.load(zhifu_ParkUrl,true);
      								    	})
      								    }
//
      						}
      					}
      				})
                    //订单详情结束
      	    	    //修改车时开始
                     var cal_end_Y=end_time.substr(0,4)
                     var cal_end_M=end_time.substr(5,2)-1
                     var cal_end_D=end_time.substr(8,2)
                     var cal_end_H=end_time.substr(11,2)
                     $("#rang-time").datetimePicker({
                         value: [cal_end_Y,cal_end_M+1, cal_end_D, cal_end_H, '00'],
                         onClose:function(){
                         	$.confirm('确认修改？', function () {
                         	 var info={
      					            parking_id:sessionStorage.parking_id_parkOrderDetails,
      					            store_id:store_id,
      					            yuan_parking_starttime:start_time,
      					            update_parking_endtime:$("#rang-time").val(),
      					            user_id:my.getCookie('id'),
      				               }
		               	           console.log(info)
		                           $.showPreloader()
      				               info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				               $.ajax({
      					url:api.updateparkingtime,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.alert("修改租期失败，请重新修改");
      						},
      				    complete:function(){
      				    	$("#rang-time").val('修改结束泊车时间')
      				    },
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									case 51013:
      									   $.modal({
                                                 title:  '您修改泊车时间后出租时间同时修改',
                                                 buttons: [
                                                             {
                                                               text: '确认',
                                                               onClick: function() {

                                                               }
                                                             },
                                                             {
                                                                text: '暂不修改',
                                                                onClick: function() {

                                                                }
                                                              },

                                                           ]
                                                      })
      									   break;
      									default:
      									   $.alert(JSON.parse(data).err_msg);
      								}
      							}else{
      								    console.log(data)
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $.alert('修改成功',function(){
      								      // $.router.reloadPage()
      								          my.reload()
      								    })


      							}
      					}
      				});
                           },
                           function(){
                           	  $("#rang-time").val('修改结束泊车时间')
                             }
                         	);
                         	//结束
                         }
                     });
                     $("#rang-time").val('修改结束泊车时间')
      	    	    //修改过车时结束
      	    	    //取消订单开始
      	    	    $('.qxdd').click(function(){
      	    	       $.confirm('确认要取消么？',function(){
      	    	       	$.showPreloader()
      	    	    $('.qxdd').addClass('active_btn')
                    var info_del={
                    	        parking_id:sessionStorage.parking_id_parkOrderDetails,
                    	        user_id:my.getCookie('id'),
                    	        is_rent:is_rent
                            }
                    console.log(info_del)
                        info_del=my.cryptoASEencrypt(JSON.stringify(info_del),key)

      				$.ajax({
      					url:api.cancelparkingorder,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info_del
      					},
      					error:function(){
      						    $.hidePreloader()
      						    $('.qxdd').removeClass('active_btn')
      							$.toast("订单取消失败");
      						},
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							$.hidePreloader()
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{
      						         $('.qxdd').removeClass('active_btn')
      						         $.alert('取消成功',function(){
      							    // $.router.loadPage("parkOrder.html");
                                         $.router.load(parkOrderUrl,true);
      						    })
      						         }
      					}
      				  })

      	    	       })

      			    })
      	    	    //取消订单结束
      	    	     //下拉刷新start
      		    $(document).off('refresh').on('refresh', '.pull-to-refresh-content',function() {
      		    	 //订单详情开始
                    var info={parking_id:sessionStorage.parking_id_parkOrderDetails}
                        info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				$.ajax({
      					url:api.parkingorderinfo,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.toast("订单详情获取失败");
      						},
      					complete:function(){
      				    	setTimeout(function(){
      				    		 $.pullToRefreshDone('.pull-to-refresh-content')
      				    	},2000)
      				    },
      					success:function(data){
      						if(data.match("err_code")!=null){
      							$.hidePreloader()
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{
      					 		        $.hidePreloader()
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    store_id=data.info.store_id
      								    start_time=data.info.parking_starttime
      								    end_time=data.info.parking_endtime
      								    $('.clxhh').text(data.info.brand_chinese_name+''+data.info.cars_name)
      								    $('.usercar_nickname').text(data.info.car_carid)
      								    $('.stores_name').text(data.info.stores_name)
      								    $('.order_startime').text(data.info.parking_starttime)
      								    $('.order_endtime').text(data.info.parking_endtime)
      								    $('.parking_price').text(data.info.parking_price)
      								    console.log(data.info.zhifu_count)
      								   if(data.info.zhifu_count!=0){
      								     	$('.zf-btn-list').empty()
      								    	for(var i=0;i<data.zhifu_button.length;i++){
      								    		if(data.zhifu_button[i].waitfp_status==0){
      								    			var list='<div class="zfxm-zf bottn btn-zf" style="margin-top: 1rem;" id="'+data.zhifu_button[i].waitfp_id+'" title="'+data.zhifu_button[i].waitfp_cost+'">待支付  '+config.danwei+data.zhifu_button[i].waitfp_cost+'</div>'
      								    			$('.zf-btn-list').append(list)
      								    		}else if(data.zhifu_button[i].waitfp_status==1)
      								    		{
      								    			var list='<div class="zfxm-xq bottn" style="margin-top: 1rem;" id="'+data.zhifu_button[i].waitfp_id+'">已支付  '+config.danwei+data.zhifu_button[i].waitfp_cost+'</div>'
      								    			$('.zf-btn-list').append(list)
      								    		}
      								    	}
      								    	$('.zfxm-zf').click(function(){
      								    		sessionStorage.park_waitfp_id=$(this).attr('id')
      								    		sessionStorage.park_parking_id=sessionStorage.parking_id_parkOrderDetails
                    	                        //$.router.loadPage("zhifu_Park.html");
                                                $.router.load(zhifu_ParkUrl,true);
      								    	})
      								    }


      						}
      					}
      				})
                    //订单详情结束
                });//下拉刷新end
});